package cn.coisini.api.admin;

import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.pojo.Menu;
import cn.coisini.model.vo.AssginMenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 菜单接口API
 */
@Tag(name = "菜单接口API", description = "一些关于菜单的操作")
@RequestMapping("/api/v1/menu")
public interface MenuControllerApi {

    @PreAuthorize("hasAuthority('menu:list')")
    @Operation(summary = "菜单列表")
    @GetMapping("/findNodes")
    Result<List<Menu>> findNodes();

    @Operation(summary = "根据id查询菜单")
    @GetMapping("/info/{id}")
    Result<Menu> info(@PathVariable("id") Long id);

    @PreAuthorize("hasAuthority('menu:add')")
    @Operation(summary = "添加菜单")
    @PostMapping("/save")
    Result<ResultEnum> saveMenu(@RequestBody Menu menu);

    @PreAuthorize("hasAuthority('menu:update')")
    @Operation(summary = "修改菜单")
    @PutMapping("/update")
    Result<ResultEnum> updateMenu(@RequestBody Menu menu);

    @PreAuthorize("hasAuthority('menu:remove')")
    @Operation(summary = "根据id删除菜单")
    @DeleteMapping("/remove/{id}")
    Result<ResultEnum> remove(@PathVariable("id") Long id);

    @Operation(summary = "根据角色获取菜单")
    @GetMapping("/toAssign/{roleId}")
    Result<List<Menu>> toAssign(@PathVariable("roleId") String id);

    @PreAuthorize("hasAuthority('role:assignAuth')")
    @Operation(summary = "给角色分配权限")
    @PostMapping("/doAssign")
    Result<ResultEnum> doAssign(@RequestBody AssginMenuVo menuVo);

    @Operation(summary = "更改菜单状态(0启用 1禁用)")
    @GetMapping("/updateStatus/{id}/{status}")
    Result<ResultEnum> status(@PathVariable("id") String id, @PathVariable("status") Boolean status);
}
